You can add an Action to the file finder if you know any BASIC.
The file finder was not designed with this in mind, so it's not necessarily the most obvious or easy extension system in the world. In fact, it's downright awful. But. Anyway. It's not that difficult.
There are three parts to the file finder:
1) The search engine scans the disc looking for a file that matches the given name, type and size.
2) The matching file is passed to the Action which does with it what it will.
3) If 'Create List' is selected (the variable file%=TRUE) and the Action has not forbidden it, the name of the file is added to the list.
All the Action needs to do is:
Have some code to initialise itself (most actions have nothing).
Have some code to verify that any parameters are correct.
Have some code to act on the found files.
You will see from the above that it is possible to write an Action that acts as a filter - e.g. checking datestamps or file contents. It should be very easy to do this.
{subhead}Structure
An Action is a fragment of a BASIC program. It must contain three procedures.
These are:
{subsub}DEFFNoktoproceed
This works out whether it is ok to start the find. The FN returns TRUE if it is, or FALSE otherwise. In normal circumstances this should simply contain the line
=TRUE
But you can use this to ask the user if they wish to continue by doing:
PROClamation("Some Text requiring a yes/no answer",-1,6)
IF query%=0 THEN=FALSE ELSE=TRUE
which will pop up a question box. If the user clicks 'No' the search will not be allowed to start.
You may also want to check that some condition is true before you start. For instance, some Actions can take parameters, which are entered in the writable icons in the window. You may need to check that the parameters are correct:
The parameters are stored in parameter$(0) - parameter$(10) so you can do
<Check that parameter is valid>
IF <parameter not valid> PROClamation("Error message",0,0):=FALSE
=TRUE
The call to PROClamation opens an error box informing the user that they are an idiot.
{subsub}DEFPROCinitfind
This is called just before the find starts, but after PROCoktoproceed. You can use this to check that all is still well. If, having done this, you want the search to carry on, include
flag%=TRUE (this is the normal case).
else include
flag%=FALSE
If it is essential that your Action produces a list of files, (for example if
you are writing a filter) then you MUST include the lines
file%=TRUE
PROCselic(Mavis%,29,0,high)
which sets the flag and selects the icon to be ON. The 'List Details' action does this (and nothing else).
{subsub}DEFPROCaction(directory$,filename$
{subsub}objtype%,filetype%,ssize%)
Once a matching file has been found the details are passed to PROCaction.
The variables are:
directory$ : The directory containing the file
filename$ : The name of the file (without the directory)
objtype% : Which is 1 if the object is a file, 2 if it's an application
or directory, and 3 if it's an image file.
filetype% : The file type of the file (eg &FFF for text files).
ssize% : (note the double s) is the size of the file, in bytes.
You may do anything you like with this information.
If you decide that the file you've got is not suitable and you don't want it to count towards the total files found, include the lines:
totalsize%-=ssize%
tot%-=1
addtolist%=FALSE
The last line informs the main routine that this file has been decided against and should not be included in a list, even if Create List is selected.
If you want extra information to be added to the list after the name of
which returns a text string containing the extra info. This text can be anything at all. You can have more than one line of extra information. When you have returned your last piece of information you MUST set
extrainfo%=FALSE
{subhead}Important bits:
The first few lines of your Action MUST be REM statements in the following form:
{tab}
REM Action:<Name of action>
REM Data:<data description> (Optional)
REM Data:<more description> (Optional)
REM Data:None
{notab}
<Name of action> is what will appear in the Action menu.
If you don't want any parameters, you should just include Data:None
THE Data AND THE None ARE CASE SENSITIVE!!!!!
If you do want to have parameters, you should make <data description> a short (about 20 characters or less) description of what the data is. This will be the label for the writable icon. The file finder will create one writable icon for each Data: item you specify.
You can also get the file finder to create an Option icon instead of a writeable icon + lable by using the format:
REM Data:<data description>,YesNo
or
REM Data:<data description>,NoYes
The difference between the two is that a YesNo icon will have its default state as 'Yes' and will set the relevant parameter$() variable to "0" for Yes and "1" for No. A NoYes icon default to 'No' and returns "0" for No and "1" for Yes. Confusing, isn't it? The FindDup (Find Duplicate Files) Action uses two option icons.
None MUST BE THE LAST ITEM OF DATA!!!
The Set Type Action uses a parameter. Looking in there is probably much easier than me explaining it.
Save your file with any name you like in the directory !BlakHole2.!FileFind.Actions.
{subhead}Potentially useful bits
To save you having to reproduce any of my hard (if shoddy) work, somePROCs that may be of use are:
{tab}
{subsub}FNreadvar(var$)
which reads the value of a system variable, returning the value as a string.
{subsub}PROClamation
which has been discussed above.
{subsub}FNftype
which takes a string and attempts to evaluate it to see if it corresponds to a known filetype. E.g. if passed the string 'text' it would return the string 'FFF'. If passed a null string, it will return a null string without causing an error, so you should check for this. If the string passed to it cannot be evaluated it will generate an error and set the variable wrinkledforeskin% to FALSE. This variable is TRUE otherwise.
{subsub}Scrap Buffer
There is an 8000 byte scrap buffer available for use. It is pointed to by the variable scrap2%
{notab}
Feel free to examine the program for any more bits. Beware of the appalling
coding and dreadful variable names. Do not alter the program in any way.
If you write a new Action do two things:
Send me a copy so I can include it (with a credit) in future releases. Accept that I can take no responsibility for maintaining it or for anything which might go wrong with it.